//
//  XMConfirmOrderMeetCell.m
//  XMJJ_zml
//
//  Created by 丁浩 on 2025/6/17.
//

#import "XMConfirmOrderMeetCell.h"

@interface XMConfirmOrderMeetCell ()

@property (nonatomic, strong) UIImageView *coverImgView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *dateLabel;
@property (nonatomic, strong) UILabel *addressLabel;

@end

@implementation XMConfirmOrderMeetCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    [self addSubview:self.coverImgView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.dateLabel];
    [self addSubview:self.addressLabel];
    
    UIImageView *dateIcon = [[UIImageView alloc] initWithFrame:CGRectMake(_coverImgView.maxX + KScaleWidth(8.0), _dateLabel.y, KScaleWidth(12.0), _dateLabel.height)];
    dateIcon.contentMode = UIViewContentModeScaleAspectFit;
    dateIcon.image = ImageNamed(@"mine_time_icon");
    [self addSubview:dateIcon];
    
    UIImageView *addressIcon = [[UIImageView alloc] initWithFrame:CGRectMake(dateIcon.x, _addressLabel.y, KScaleWidth(KScaleWidth(12.0)), _addressLabel.height)];
    addressIcon.contentMode = UIViewContentModeScaleAspectFit;
    addressIcon.image = ImageNamed(@"mine_address_icon");
    [self addSubview:addressIcon];
}

//见面箱数据
- (void)setContentWithServiceModel:(XMServiceVosModel *)serviceModel {
    if (!serviceModel.addr_province) {
        serviceModel.addr_province = @"";
    }
    if (!serviceModel.addr_city) {
        serviceModel.addr_city = @"";
    }
    [_coverImgView sd_setImageWithURL:[NSURL URLWithString:serviceModel.img]];
    _titleLabel.text = serviceModel.title;
    _dateLabel.text = [[NSDate dateWithTimeIntervalSince1970:[serviceModel.time integerValue]] dateStringWithFormat:@"yyyy.MM.dd HH:mm"];
    _addressLabel.text = [NSString stringWithFormat:@"%@%@%@", serviceModel.addr_province, serviceModel.addr_city, serviceModel.addr_detail];
}

//直接下单数据
- (void)setContentWithMeetDetailModel:(XMMeetDetailModel *)meetDetailModel {
    [_coverImgView sd_setImageWithURL:[NSURL URLWithString:meetDetailModel.coverImageUrl]];
    _titleLabel.text = meetDetailModel.title;
//    _dateLabel.text = [[NSDate dateWithTimeIntervalSince1970:[meetDetailModel.startTimeStr integerValue]/1000] dateStringWithFormat:@"yyyy.MM.dd HH:mm"];
    _dateLabel.text = [meetDetailModel.startTimeStr stringByReplacingOccurrencesOfString:@"/" withString:@"."];
    if (!meetDetailModel.addrProvince) {
        meetDetailModel.addrProvince = @"";
    }
    if (!meetDetailModel.addrCity) {
        meetDetailModel.addrCity = @"";
    }
    if (!meetDetailModel.addrDetail) {
        meetDetailModel.addrDetail = @"";
    }
    _addressLabel.text = [NSString stringWithFormat:@"%@%@%@", meetDetailModel.addrProvince, meetDetailModel.addrCity, meetDetailModel.addrDetail];
}

//订单数据
- (void)setContentWithOrderDetailModel:(XMOrderDetailModel *)orderDetailModel {
    [_coverImgView sd_setImageWithURL:[NSURL URLWithString:orderDetailModel.coverImageUrl]];
    _titleLabel.text = orderDetailModel.title;
    _dateLabel.text = [[NSDate dateWithTimeIntervalSince1970:[orderDetailModel.startTime integerValue]/1000] dateStringWithFormat:@"yyyy.MM.dd HH:mm"];
    _addressLabel.text = orderDetailModel.address;
}

#pragma mark - Init
- (UIImageView *)coverImgView {
    if (!_coverImgView) {
        _coverImgView = [[UIImageView alloc] initWithFrame:CGRectMake(KScaleWidth(16.0), KScaleWidth(10.0), KScaleWidth(80.0), KScaleWidth(80.0))];
        [_coverImgView setCornerRadius:KScaleWidth(8.0)];
    }
    return _coverImgView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.coverImgView.maxX + KScaleWidth(8.0), _coverImgView.y, self.width - _coverImgView.maxX - KScaleWidth(8.0), KScaleWidth(30.0)) font:KFontSize(16.0) textColor:kColorHEX(0x333333)];
    }
    return _titleLabel;
}

- (UILabel *)dateLabel {
    if (!_dateLabel) {
        _dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.coverImgView.maxX + KScaleWidth(28.0), self.titleLabel.maxY, self.width - _coverImgView.maxY - KScaleWidth(28.0), KScaleWidth(28.0)) font:KFontSize(13.0) textColor:kColorHEX(0x666666)];
    }
    return _dateLabel;
}

- (UILabel *)addressLabel {
    if (!_addressLabel) {
        _addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.dateLabel.x, _dateLabel.maxY, _dateLabel.width, KScaleWidth(20.0)) font:KFontSize(13.0) textColor:kColorHEX(0x666666)];
    }
    return _addressLabel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
